<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .container {
        display: flex;
      }
      .box1 {
        width: 5rem;
        height: 2.66667rem;
        background-color: red;
      }
      .box2 {
        width: 5rem;
        height: 2.66667rem;
        background-color: green;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box1"></div>
      <div class="box2"></div>
    </div>
    <script>
      /*
        设计稿已知元素大小，如100px（y），如何转rem单位？
          x = y / 37.5

        基于webpack脚手架开发，插件px2rem来自动转化
      */
      function setFontSize() {
        const clientWidth = document.documentElement.clientWidth;
        const val = clientWidth / 10;
        document.documentElement.style.fontSize = val + "px";
      }

      setFontSize();
      // 窗口调整事件
      window.onresize = setFontSize;
    </script>
  </body>
</html>
